package com.malamute.core.interceptor;

import java.util.Map;

import org.apache.log4j.Logger;

import com.malamute.core.constant.SystemConstant;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class CheckCustomerLoginInterceptor implements Interceptor {

	Logger log = Logger.getLogger(CheckCustomerLoginInterceptor.class);

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.opensymphony.xwork2.interceptor.AbstractInterceptor#intercept(com
	 * .opensymphony.xwork2.ActionInvocation)
	 */

	@Override
	public String intercept(ActionInvocation actionInvocation) throws Exception {
		log.debug("CheckCustomerLoginInterceptor intercept");
		log.info(actionInvocation.getInvocationContext().getName());// actionname
		log.info(actionInvocation.getProxy().getNamespace());// namespace
		String nameSpace = actionInvocation.getProxy().getNamespace();
		String actionName = actionInvocation.getInvocationContext().getName();
		log.debug(actionName);
		if (("/web".equals(nameSpace) && (actionName.indexOf("webview") != -1 || actionName
				.indexOf("shopcart") != -1))) {
			return actionInvocation.invoke();
		}
		Map session = actionInvocation.getInvocationContext().getSession();
		Object obj = session.get(SystemConstant.SES_CUSTOMER_LOGIN);
		// ACE:以下内容注释，暂时不拦截
		if (obj == null) {
			if (log.isDebugEnabled()) {
				return actionInvocation.invoke();
			} else {
				log.debug("Customer not Login");
				return "customerLogin";
			}

		} else {
			log.debug("Customer has Login");
			return actionInvocation.invoke();
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.interceptor.Interceptor#destroy()
	 */
	@Override
	public void destroy() {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.interceptor.Interceptor#init()
	 */
	@Override
	public void init() {
		// TODO Auto-generated method stub

	}

}
